const app = getApp()
const $api = require('../../../utils/api.js').API;

Page({
    data: {
        page: 1,
        noneShow:false,
        list:[],
        pageShow:true,
        imgUrl:app.globalData.imgUrl,
        seeNum:0,
    },
    onLoad:function(){
        wx.showLoading()
        this.getlist();
        this.getSeeNum()
    },
    getSeeNum:function(){
        var data ={'uid':wx.getStorageSync('uid')}
        var that = this
        $api.get('vip/seeNum',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                that.setData({
                    seeNum:res.data.data
                })
            }
        })
    },
    getlist: function(){
        var that = this
        var data ={'uid':wx.getStorageSync('uid'),
            'page':this.data.page
        }
        $api.get('vip/buyLIst',data).then(res => {
            wx.hideLoading()
            if(res.data.code == 1){
                if(res.data.data.total == 0){
                    that.setData({
                        noneShow:true
                    })
                }else{
                    that.setData({
                        noneShow:false
                    })
                }
                if(res.data.data.last_page <= that.data.page){
                    that.setData({
                        pageShow:false
                    })
                }
                if(that.data.page == 1){
                    that.setData({
                        list:res.data.data.data
                    })
                }else{
                    that.setData({
                        list:list.concat(res.data.data.data)
                    })
                }
            }
        })
    },
    onReachBottom: function(t){
        if(this.data.pageShow){
            //当前不是最后一页可加载
            this.setData({
                page: this.data.page + 1,
            })
        this.getlist();
        }
    },
    onShareAppMessage: function() {
        return {
            title: "天意美业直通车",
            path: "/pages/index/index?puid="+wx.getStorageSync('uid')
        };
    },
    jump:function(e){
        var name = e.currentTarget.dataset.name;
        wx.navigateTo({
            url:name
        })
    }
});